$(function() {
  var err=$('#neterror').css('display','none');
  if(!isLocalStorageNameSupported()){
    new UserPrompt('您的运行环境不支持本地离线缓存');
    return;
  }
  localCache.clear();
  var search=decodeURI(window.location.search.substr(1)),
  accountIdentify=matchQueryString(search,'cust_account'),
  accountIdentifer=matchQueryString(search,'app_key'),
  color=matchQueryString(search,'color'),
  index=matchQueryString(search,'index');
  var params=matchQueryString(search,'params');
  if(params!==''){
	  params=getJSONParsedObject(params,'参数格式错误');
  }else
	  params=[];
  
  if(color){
	  localCache.setSessionItems({
		  color:'#'+color
	  });
  }
  localCache.load(false);//加载基本缓存参数
  var base={
      type: "post",
      url: localCache.getSessionItem('check_url'),
      dataType: "json",
      async:true,
      data:{
    	cust_account:accountIdentify,
    	app_key:accountIdentifer,
        sign:matchQueryString(search,'sign'),
        timestamp:matchQueryString(search,'timestamp')
      },
      complete:function(xhr,status){
        if(loadPrompt){
          loadPrompt.close();
          loadPrompt=null;
        }
      },
      beforeSend:function(){
        loadPrompt=new LoadPrompt('正在校验账户信息，请稍候...');           
      },
      success: function(rc){
        if(rc.code==='0000'){//校验通过，进入首页
          index=(index==='')?3:Number(index);
          //调用接口缓存用户数据
          localCache.setSessionItems({
            account_identify:accountIdentify,
            index:index,
            periphery_code:rc.periphery_code,
            periphery_account:rc.cust_account,
            companyName:params.ext_orgName
          },params);                
          router(index);       
        }else{//其他参数异常
          new UserPrompt(rc.describe);
        }
      }
  };    
      
  err.on('click',function(){
    dispatch(null);
  });

  function dispatch(parameters){
    $.ajax($.extend({},base,parameters));
  }
  
  dispatch({
    error:function(xhr,status,error){
      if(status==='error'){
          handlerError('netconnectionerror',function(){
            err.css('display','');
        });           
      }else{
        //调用接口异常
      }
   }
  });
 }
)



